package com.dongdongshop.service.impl;

import com.dongdongshop.pojo.vo.Comment;
import com.dongdongshop.service.commen.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@com.alibaba.dubbo.config.annotation.Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void insertComment(Comment comment) {
        mongoTemplate.save(comment);
    }

    @Override
    public List<Comment> getComment() {
        return mongoTemplate.find(new Query().limit(2).skip(0),Comment.class);
    }

    @Override
    public void incComment(String id, Integer inc) {
        mongoTemplate.updateMulti(
                new Query(Criteria.where("_id").is(id))
                ,new Update().inc("ikedNum",inc)
                ,Comment.class);
    }
}
